package com.lottery.ruok.lottrey.dialog;

import android.animation.Animator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.airbnb.lottie.LottieAnimationView;
import com.applozic.mobicomkit.ChatConfig;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.AccountDetailActivity;
import com.lottery.ruok.lottrey.activity.GetPacketResultActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/8/2.
 */

public class RedPacketAniDialog extends Activity {
    @BindView(R.id.anim)
    LottieAnimationView anim;
    private String flag;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.red_ani_layout);

        ButterKnife.bind(this);
        Intent intent = getIntent();
        flag = intent.getStringExtra("flag");

    }

    @Override
    protected void onResume() {
        super.onResume();

        anim.playAnimation();
        anim.useHardwareAcceleration(true);
        anim.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                anim.enableMergePathsForKitKatAndAbove(true);
                try {
                    if (flag == null) {
                        Intent intent = new Intent(RedPacketAniDialog.this, GetPacketResultActivity.class);
                        intent.putExtra(ChatConfig.PACKET_GET_ID, getIntent().getStringExtra(ChatConfig.PACKET_GET_ID));
                        intent.putExtra(ChatConfig.PACKET_ID, getIntent().getStringExtra(ChatConfig.PACKET_ID));
                        startActivity(intent);
                    } else {
                        Intent intent_red = new Intent(RedPacketAniDialog.this, AccountDetailActivity.class);
                        startActivity(intent_red);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

                finish();
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
    }

    @Override
    public void onBackPressed() {

    }
}
